<?php
/**
 * 话术类容管理
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/12/8
 * Time: 14:45
 */

namespace app\api\model;


class WorkWord extends BaseModel
{
        protected $autoWriteTimestamp = true;
        protected $hidden=['w_id','c_id','create_time','update_time','delete_time'];
    /**
     * 添加话术类容
     * @param $info
     * @return false|int
     */
        public static function addWord($info){
            $word = new WorkWord();
            $result =  $word->save($info);
            return $result;
        }

    /**
     * 获取话术
     * @param $id
     * @return null|static
     */
        public static function getWord($id){
            return self::get($id);
        }

    /**
     * 更新话术库
     * @param $info
     * @param $id
     * @return false|int
     */
        public static function updateWord($info,$id){
            $word = new WorkWord();
            $where['id'] = $id;
            $result = $word->save($info,$where);
            return $result;
        }

    /**
     * 删除话术库
     * @param $id
     * @return int
     */
        public static function deleteWord($id){
            $word = new WorkWord();
            $result = $word->destroy($id);
            return $result;
        }
    /**
     * 获取话术列表
     * @param $t_id
     * @return false|\PDOStatement|string|\think\Collection
     */
        public static function getWordList($t_id,$c_id){
            $word = new WorkWord();
            $result = $word->where('t_id','=',$t_id)
                ->where('c_id','=',$c_id)
                ->where('w_id = 0')
                ->select();
            return $result;
        }

    /**
     * 获取用户自定义话术列表
     * @param $uid
     * @return false|\PDOStatement|string|\think\Collection
     */
        public static function getWordByCategory($uid,$categoryId){
            $user = WorkUser::getUserByWuID($uid);
            $t_id = $user->t_id;
            $word = new WorkWord();
            $result =  $word->where('t_id','=',$t_id)
                ->where('c_id','=',$categoryId)
                ->where("w_id = 0")
                ->select();
            return $result;
        }

    /**
     * 用户添加自定义话术
     * @param $info
     * @return false|int
     */
        public static function addUserWord($info,$uid){
            $user = WorkUser::getUserByWuID($uid);
            $t_id = $user->t_id;
            $info['t_id'] = $t_id;
            $info['w_id'] = $uid;
            $word = new WorkWord();
            $result = $word->save($info);
            return $result;
        }

    /**
     * 更新用自定义话术
     * @param $info
     * @param $uid
     * @return false|int
     */
        public static function updateUserWord($info,$uid){
            $user = WorkUser::getUserByWuID($uid);
            $t_id = $user->t_id;
            $info['t_id'] = $t_id;
            $info['w_id'] = $uid;
            $word = new WorkWord();
            $where=['id'=>$info['id']];
            $result = $word->save($info,$where);
            return $result;
        }

    /**
     * 查询自定义话术列表
     * @param $uid
     * @return false|\PDOStatement|string|\think\Collection
     */
        public static function getUserWordList($uid){
            return self::where('w_id','=',$uid)->select();
        }


}